<?php

namespace App\Model;

use Illuminate\Database\Eloquent\Model;

class System extends Model
{
    protected $table = 'system';
    public $timestamps = false;
    protected $guarded = [];
    
    // 获取网站配置项
    public static function getConfigs()
    {
        $data = System::orderBy('pid','asc')
                ->orderBy('sort', 'asc')
                ->get();
        $configs = [];
        foreach($data as $k=>$v){
            if($v->type == 'radio'){
                $value = explode(',', $v->value_range);
                $kv = [];
                foreach($value as $vv){
                    $tmp = explode('|', $vv);
                    $kv[$tmp[0]] = $tmp[1];
                }
                $v->kv = $kv;
            }
            $configs[$v->pid][] = $v;
        }
        unset($data);
//        dd($configs);
        return $configs;
    }
}
